﻿Imports Negocio
Imports Excepciones

Public Class DataGridViewExt
    Inherits DataGridView
    Implements IControlTranslatable

    Sub New()
        MyBase.New()
        'Default values
        Me.AllowUserToAddRows = False
        Me.AllowUserToDeleteRows = False
        Me.AllowUserToOrderColumns = True
        Me.AutoGenerateColumns = False
        Me.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill
        Me.BackgroundColor = System.Drawing.Color.White
        Me.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.GridColor = System.Drawing.Color.White
        Me.MultiSelect = False
        Me.RowHeadersVisible = False
        Me.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect
    End Sub

    Public Sub Translate(ctrls As List(Of Control)) Implements IControlTranslatable.Translate
        Try
            Dim ctrl As Control = ctrls.Find(AddressOf FindByControlName)
            Dim headers As String() = ctrl.Caption.Split("|")

            For i As Integer = 0 To headers.Count - 1
                Me.Columns(i).HeaderText = headers(i)
            Next
        Catch ex As Exception
            Throw New ControlNotSupportedLocalizationException()
        End Try
        Throw New ControlFoundLocalizationException()
    End Sub

    Private Function FindByControlName(ctrl As Control) As Boolean
        If ctrl.Nombre = Me.Name Then
            Return True
        Else
            Return False
        End If
    End Function

End Class
